[Gamesnws-commits] r18 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 10 12:35:11 CEST 2009


Author: grafab
Date: 2009-08-10 12:35:10 +0200 (Mon, 10 Aug 2009)
New Revision: 18

Modified:
   pkg/R/adminUno.R
   pkg/R/playUno.R
Log:
Uno has to be said, before laying down the second-last card. When not, 2 penalty-cards are given.
When you say "uno" without playin the second-last card, after that, you get 1 penalty-card.
The command is "say-uno"

Modified: pkg/R/adminUno.R
===================================================================
--- pkg/R/adminUno.R	2009-08-10 08:37:33 UTC (rev 17)
+++ pkg/R/adminUno.R	2009-08-10 10:35:10 UTC (rev 18)
@@ -18,6 +18,7 @@
 	nwsDeclare(ws, 'penalty', 'single')	#if one player got penalty but can not play a card, next player should not get penalty too
 	nwsDeclare(ws, 'debug' , 'single') 	# boolean for debug-mode
 	nwsDeclare(ws, 'points', 'single') 	# vector of points, in order of players_logedin
+	nwsDeclare(ws, 'uno' , 'single')  #vector of uno-booleans, in order of players_logedin 
 	
   # user declares own variable for his hand-cards in .playUnoMaster()
 
@@ -156,7 +157,14 @@
   	#Set startvalue for variable penalty
   	#FALSE = penalty not allready given, TRUE = penalty has been given to a player -> not again!
  	 nwsStore(ws, 'penalty', TRUE)
-	
+ 	 
+ 	 #set startvalues for uno-vector
+ 	 uno<-vector()
+ 	 for(i in 1:length(nwsFindTry(ws, 'players_logedin', c(1:10)))){
+ 	 uno<-c(uno,FALSE)
+ 	 }
+ 	 nwsStore(ws, 'uno',uno)
+ 	 
 	# set player_in_action and start game
 	nwsStore(ws, 'player_in_action', players[length(players)])
 	

Modified: pkg/R/playUno.R
===================================================================
--- pkg/R/playUno.R	2009-08-10 08:37:33 UTC (rev 17)
+++ pkg/R/playUno.R	2009-08-10 10:35:10 UTC (rev 18)
@@ -87,7 +87,8 @@
 				#cat("	Handkarten:",cards_hand,"\n")
 				for(p in players){
 			  points <- nwsFindTry(ws,'points')
-		    cat("	>>",p, " - (",length(nwsFindTry(ws,p))," card(s), ",points[p]," point(s))<< ", sep="")
+			  uno<-nwsFindTry(ws,'uno')
+		    cat("	>>",p, " - (",length(nwsFindTry(ws,p))," card(s), ",points[p]," point(s), uno = ",uno[p],"<< ", sep="")
 		    }
 		    cat("\n")
 		  }
@@ -239,6 +240,9 @@
 	
 	playerInAction <- user
 	
+	unovec<-nwsFindTry(ws, 'uno')
+	names(unovec)<- nwsFindTry(ws,'players_logedin')
+	
 	if(card_play=="NO"){
 		# if there is no matching card in the hand
 		if(NO==0){
@@ -256,13 +260,30 @@
 			nwsStore(ws, 'player_in_action', playerInAction)
 			#card_play=NO
 		}
-		
-	}else if(card_play=="rybg-0"){# && played_color == card_play_color){
+    	
+	}else if(card_play=="say-uno"){  #before playing second-last card
+    card_play<-""
+    unovec[playerInAction]<-TRUE
+        
+  }else if(card_play=="rybg-0"){# && played_color == card_play_color
 		#remove card from hand
 		cards_hand <- cards_hand[-which(cards_hand==card_play)]
 		nwsStore(ws, user, cards_hand)
 		# play card
 		nwsStore(ws, 'played', card_play_save)
+    if(length(cards_hand) == 1 && !unovec[playerInAction]){
+    cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)
+    }	
+    else if(length(cards_hand) != 1 && unovec[playerInAction]){
+    cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)    
+    }
+    unovec[playerInAction]<-FALSE
+    
 		#check for winner and goto next player
 		if(length(cards_hand) != 0 ){
 			# rotate player
@@ -278,6 +299,18 @@
 		nwsStore(ws, user, cards_hand)
 		# play card
 		nwsStore(ws, 'played', card_play_save)
+    if(length(cards_hand) == 1 && !unovec[playerInAction]){
+    cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)
+    }	
+    else if(length(cards_hand) != 1 && unovec[playerInAction]){
+    cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)    
+    }
+    unovec[playerInAction]<-FALSE
 		#penalty has not been given
     		nwsStore(ws, 'penalty', FALSE)
 		#check for winner and goto next player
@@ -295,6 +328,18 @@
 		nwsStore(ws, user, cards_hand)
 		# play card
 		nwsStore(ws, 'played', card_play_save)
+    if(length(cards_hand) == 1 && !unovec[playerInAction]){
+    cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)
+    }	
+    else if(length(cards_hand) != 1 && unovec[playerInAction]){
+    cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)    
+    }
+    unovec[playerInAction]<-FALSE
 		#check for winner and goto next player
 		if(length(cards_hand) != 0 ){
 			# rotate player 2 times
@@ -311,7 +356,19 @@
 		cards_hand <- cards_hand[-which(cards_hand==card_play)]
 		nwsStore(ws, user, cards_hand)
 		# play card
-		nwsStore(ws, 'played', card_play_save) 
+		nwsStore(ws, 'played', card_play_save)
+    if(length(cards_hand) == 1 && !unovec[playerInAction]){
+    cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)
+    }	
+    else if(length(cards_hand) != 1 && unovec[playerInAction]){
+    cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)    
+    }
+    unovec[playerInAction]<-FALSE 
 		#check for winner
     		if(length(cards_hand) != 0 ){
 	    	#if there are only two players, they just don´t have to rotate
@@ -339,7 +396,19 @@
 		cards_hand <- cards_hand[-which(cards_hand==card_play)]
 		nwsStore(ws, user, cards_hand)
 		# play card
-		nwsStore(ws, 'played', card_play_save)  
+		nwsStore(ws, 'played', card_play_save)
+    if(length(cards_hand) == 1 && !unovec[playerInAction]){
+    cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)
+    }	
+    else if(length(cards_hand) != 1 && unovec[playerInAction]){
+    cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)    
+    }
+    unovec[playerInAction]<-FALSE  
 		#penalty has not been given
     		nwsStore(ws, 'penalty', FALSE)
 		#check for winner and goto next player
@@ -356,7 +425,19 @@
 		cards_hand <- cards_hand[-which(cards_hand==card_play)]
 		nwsStore(ws, user, cards_hand)
 		# play card
-		nwsStore(ws, 'played', card_play_save)  
+		nwsStore(ws, 'played', card_play_save)
+    if(length(cards_hand) == 1 && !unovec[playerInAction]){
+    cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)
+    }	
+    else if(length(cards_hand) != 1 && unovec[playerInAction]){
+    cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)    
+    }
+    unovec[playerInAction]<-FALSE  
 		#penalty has not been given
     		nwsStore(ws, 'penalty', FALSE)
 		#check for winner and goto next player
@@ -379,6 +460,19 @@
 		nwsStore(ws, user, cards_hand)
 		# play card
 		nwsStore(ws, 'played', card_play_save)
+		
+    if(length(cards_hand) == 1 && !unovec[playerInAction]){
+    cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)
+    }	
+    else if(length(cards_hand) != 1 && unovec[playerInAction]){
+    cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
+    cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+	  nwsStore(ws, user, cards_hand)    
+    }
+    unovec[playerInAction]<-FALSE
 		#check for winner and goto next player
 		if(length(cards_hand) != 0 ){
 			# rotate player
@@ -394,6 +488,8 @@
 
 	} else
 		warning("Error : unknown use case!")
+
+  nwsStore(ws, 'uno',unovec)
 	return(list(card_play, NO))
 }
 ##################################################
@@ -414,6 +510,7 @@
 		pointsvec<-tmp
 	}
 	names(pointsvec)<-nwsFindTry(ws,'players_logedin')
+	
 	for(p in nwsFindTry(ws,'players_logedin')){
 	#Summarize Handcards
 		cards_hand<-nwsFindTry(ws,p)



More information about the Gamesnws-commits mailing list