You need to sign in to do that
Don't have an account?
Unsure why not working
Working on a Rock Paper Scissors game to learn Apex/visualforce with (and to be able to play with other devs on the org). Somewhere in the main body, something is not working right. It is running, that much I know, but somewhere down the line it is not updating the page nor the database as to the result. Here is the VF page:
<apex:page showheader="false">
<c:rps ></c:rps>
</apex:page>
Here is the Component:
<apex:component controller="rps" allowDML="true"> Lets play Rock Paper Scissors! <apex:form > <apex:selectList id="rps" value="{!input}" size="1" title="Choose Your Weapon"> <apex:selectOptions value="{!inputSelect}"/> </apex:selectList> <apex:selectList id="rps2" value="{!partners}" size="1" title="Choose Your Weapon"> <apex:selectOptions value="{!partner}"/> </apex:selectList> <apex:commandButton action="{!makeNew}" value="Create Game"/> <apex:commandButton action="{!makePlayable}" value="Allow Multiplayer"/> </apex:form> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Play" action="{!processSelected}" rerender="table"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!ListAvailable}" var="a" id="table"> <apex:column > <apex:inputCheckbox value="{!a.selected}"/> </apex:column> <apex:column value="{!a.game.Name}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> <apex:outputPanel id="dynamic"> {!output}<br/> </apex:outputPanel> </apex:component>
Here is the controller class:
public class rps{
public PageReference makeNew(){
Asynch_RPS_Game__c a = new Asynch_RPS_Game__c();
a.move__c = input;
a.user2__c = partners;
INSERT a;
return null;
}
public List<SelectOption> getPartner(){
List<selectOption> op = new List<selectOption>();
for(RPS_Save__c rps : [SELECT Name FROM RPS_Save__c WHERE MakePlayable__c = true]){
op.add(new selectOption(rps.Name,rps.Name));
}
System.debug('op: ' + op);
return op;
}
//Gives options to click
public List<SelectOption> getinputSelect(){
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('rock','Rock'));
options.add(new selectOption('paper','Paper'));
options.add(new selectOption('scissors','Scissors'));
return options;
}
public String partners {get;set;}
public String input {get;set;}
public String output {get;set;}
public integer wins {get;set;}
public integer losses {get;set;}
public integer ties {get;set;}
private RPS_Save__c userScore;
public List<aAsynch_RPS_Game> gamesList {get;set;}
//allows the multiplayer
public PageReference makePlayable(){
RPS_Save__c[] userScores = [SELECT id FROM RPS_Save__c WHERE Name=:userInfo.getName()];
if(userScores.size() > 0){
userScore = userScores[0];
} else {
userScore = new RPS_Save__c(Name = userInfo.getName(), Wins__c = 0, Losses__c = 0, Ties__c = 0);
INSERT userScore;
}
userScore.makePlayable__c = true;
UPDATE userScore;
return null;
}
//Lists games that still need to be finished
public List<aAsynch_RPS_Game> getListAvailable(){
if(gamesList == null) {
gamesList = new List<aAsynch_RPS_Game>();
for(Asynch_RPS_Game__c a : [SELECT Name, Owner.Name, Move__c, Finished__c FROM Asynch_RPS_Game__c WHERE User2__c =: userInfo.getName()]) {
if(a.Finished__c == null){
gamesList.add(new aAsynch_RPS_Game(a));
}
}
}
return gamesList;
}
//does stuff when you select things
public PageReference processSelected(){
system.debug('is this even running?');
List<Asynch_RPS_Game__c> available = new List<Asynch_RPS_Game__c>();
for(aAsynch_RPS_Game ggame : getListAvailable()){
if(ggame.selected == true){
available.add(ggame.game);
system.debug('sup from avail.add');
}
}
integer l;
integer w;
integer t;
RPS_Save__c[] userScores = [SELECT id, Wins__c, Losses__c, Ties__c, Name FROM RPS_Save__c WHERE Name=:userInfo.getName()];
if(userScores.size() > 0){
userScore = userScores[0];
w = integer.valueOf(userScore.Wins__c);
l = integer.valueOf(userScore.Losses__c);
t = integer.valueOf(userScore.Ties__c);
} else {
userScore = new RPS_Save__c(Name = userInfo.getName(), Wins__c = 0, Losses__c = 0, Ties__c = 0);
INSERT userScore;
}
for(Asynch_RPS_Game__c a : available){
integer comp;
if(a.move__c == 'rock'){
comp = 0;
}else if(a.move__c == 'paper'){
comp = 1;
}else{
comp = 2;}
//check win/loss/tie
if(comp == 0){
if(input == 'rock'){
output = 'Tie';
if(t > 0){
t++;
}else{
t = 1;
}
return null;
}else if(input == 'paper'){
output = 'Win';
if(w > 0){
w++;
}else{
w = 1;
}
return null;
}else if(input == 'scissors'){
output = 'Lose';
if(l > 0){
l++;
}else{
l = 1;
}
return null;
}else{
output = ' ';
return null;
}
}else if(comp == 1){
if(input == 'rock'){
output = 'Lose';
if(l > 0){
l++;
}else{
l = 1;
}
return null;
}else if(input == 'paper'){
output = 'Tie';
if(t > 0){
t++;
}else{
t = 1;
}
return null;
}else if(input == 'scissors'){
output = 'Win';
if(w > 0){
w++;
}else{
w = 1;
}
return null;
}else{
output = ' ';
return null;
}
}else{
if(input == 'rock'){
output = 'Win';
if(w > 0){
w++;
}else{
w = 1;
}
return null;
}else if(input == 'paper'){
output = 'Lose';
if(l > 0){
l++;
}else{
l = 1;
}
return null;
}else if(input == 'scissors'){
output = 'Tie';
if(t > 0){
t++;
}else{
t = 1;
}
return null;
}else{
output = ' ';
return null;
}
}
a.Finished__c = System.Today();
UPDATE a;
}
userScore.Wins__c = w;
userScore.Losses__c = l;
userScore.Ties__c = t;
userScore.Name = userInfo.getName();
UPDATE userScore;
available = null;
return null;
}
//wrapper class for list
public class aAsynch_RPS_Game {
public Asynch_RPS_Game__c game {get; set;}
public Boolean selected {get; set;}
public aAsynch_RPS_Game(Asynch_RPS_Game__c g){
game = g;
selected = false;
}
}
}
Any help given is greatly appreciated!
Free Fire Apk (https://freefireapk.download)